if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.groups.Add")) {


    /**
     *
     */
    jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.userMgt.groups.Add",
            jsx3.gui.LayoutGrid,
            null,
            function (add) {

                add.prototype.initialize = function() {
                    this.parentGroupId = null
                    // set the window instance
                    if (jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.window.Window")) {
                        // set the window instance
                        this.window = this.getAncestorOfType(tibco.admin.enterpriseAssets.userMgt.window.Window)
                        if (this.window) {
                            this.setWindowId(this.window.getId());
                        }
                    }
                    this.subscribeAll()

					this.passedItems["groupName"] = false;//070818
					this.passedItems["groupDesc"] = true;//070818
                }

                add.prototype.subscribeAll = function() {
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.userMgt.EventID.ADD_ITEM_REQUIRED, this, this.setParentGroupId);
                }

                add.prototype.unsubscribeAll = function() {
                    tibco.admin.PubSub.unsubscribe(tibco.admin.enterpriseAssets.userMgt.EventID.ADD_ITEM_REQUIRED, this);
                }

                add.prototype.setWindowId = function(strId) {
                    this.windowId = strId
                }


                add.prototype.getWindowId = function() {
                    return this.windowId
                }

                add.prototype.setParentGroupId = function(objEvent) {
                    if (objEvent.windowId == this.getWindowId()) {
                        this.parentGroupId = objEvent.parentItem
                    }
                }

                //call this method to begin the service call (eg.service.calladdUser();)
                add.prototype.calladdGroup = function() {
                    this.adduservalidate = true
                    tibco.admin.util.Log.USERMGT.trace("tibco.admin.enterpriseAssets.userMgt.groups.Add#calladdGroup")
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/groups/rules/addGroup.xml", "addGroup", "Add Group");

                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onaddGroupSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.onaddGroupError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.onaddGroupInvalid);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                    //objService.groupname = this.getDescendantOfName("tbxGroupName_24_F_Add").getValue();
                    objService.parentgroupid = this.parentGroupId
                    objService.getServiceMessage();

                    if (this.adduservalidate) {
                        objService.doCall(true);
                    }
                };

                add.prototype.onaddGroupSuccess = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.trace("tibco.admin.enterpriseAssets.userMgt.user.Add#onaddGroupSuccess");
                    tibco.admin.util.Log.USERMGT.trace("objEvent.target.simpleActionResponse ")
                    if (objEvent.target.simpleActionResponse == "true") {
                        this.resetPasswordFieled()
                        this.getDescendantOfName("blkServerMessages_24_F_Add").setDisplay(jsx3.gui.Block.DISPLAYNONE, true)
                        // Publish a message to window
                        var msg = new Object();
                        msg.subject = tibco.admin.enterpriseAssets.userMgt.EventID.ADD_ITEM_SUCCESS
                        msg.windowId = this.getWindowId();

                        msg.parentItem = this.parentGroupId;
                        msg.addedItem = objEvent.target.addedItemId

                        tibco.admin.PubSub.publish(msg);
                    }
                    else {
                        this.getDescendantOfName("blkServerMessages_24_F_Add").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true)
                        this.getDescendantOfName("lblMessage_24_F_Add").
								setText(tibco.admin.Main.getServer().getDynamicProperty("@@faildAddGroup_24_F_Add") + objEvent.target.groupname, true)
                    }

                };

                add.prototype.onaddGroupError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                    this.getDescendantOfName("blkServerMessages_24_F_Add").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true)
                    this.getDescendantOfName("lblMessage_24_F_Add").
							setText(tibco.admin.Main.getServer().getDynamicProperty("@@serverError_24_F_Add"), true)

                };

                add.prototype.onaddGroupInvalid = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.info("Invalid: The following message node just failed validation:\n\n"+objEvent.message)
                    this.adduservalidate = false;
                    this.getDescendantOfName("blkServerMessages_24_F_Add").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true)
                    this.getDescendantOfName("lblMessage_24_F_Add").
							setText(tibco.admin.Main.getServer().getDynamicProperty("@@namingError_24_F_Add"), true)
                    this.repaint();
                    tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };

                add.prototype.cancelAddGroup = function(master) {
                    this.resetPasswordFieled()
                    this.getDescendantOfName("blkServerMessages_24_F_Add").setDisplay(jsx3.gui.Block.DISPLAYNONE, true)
                    // Publish a message to window
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.userMgt.EventID.ADD_ITEM_CANCELED
                    msg.master = master
                    msg.windowId = this.getWindowId();
                    tibco.admin.PubSub.publish(msg);
                }

               add.prototype.resetPasswordFieled = function() {
                    this.getDescendantOfName("tbxGroupName_24_F_Add").setValue("").repaint()
                    this.getDescendantOfName("tbxGroupDescription_24_F_Add").setValue("").repaint()
                }

				/*070818
				* if user doesn't fishish all the required fields, the "save" button will be disabled.
				*/
				add.prototype.passedItems = {};

                add.prototype.valiGroupName = function(obj, strValue) {
                    this.passedItems["groupName"] = tibco.admin.util.Validation.doValidateNotEmptyNoWhSpace(obj, strValue, tibco.admin.Main.getServer().getDynamicProperty("@@comName_24"));
					this.enableSaveBtn4Add();
				};

                add.prototype.valiGroupDesc = function(obj, strValue) {
                    this.passedItems["groupDesc"] = tibco.admin.util.Validation.doValidateNotEmpty(obj, strValue, tibco.admin.Main.getServer().getDynamicProperty("@@comDesc_24"));
					this.enableSaveBtn4Add();
				};

                add.prototype.enableSaveBtn4Add = function() {
					var allPassed = true;
					for (var item in this.passedItems) {
						if(!this.passedItems[item]) allPassed = false;
					}
					if(allPassed) this.getDescendantOfName("btnSave_24_F_Add").setEnabled(jsx3.gui.Form.STATEENABLED, true);
					else this.getDescendantOfName("btnSave_24_F_Add").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
				}

            });
}